<template>
	<view class="pagesBox">
		<block v-for="(item,index) in noticeList" :key="index">
			<view class="pagesMain" @click="toNoticeDetail(item)">
				<view class="noticeTitle">
					<image :src="`${baseUrl}/static/index/icon02.png`" style="width: 32rpx;height: 32rpx;flex-shrink: 0;"></image>
					<view class="u-line-1" style="margin-left: 6rpx;flex: 1;">{{item.title}}</view>
				</view>
				<view class="noticeContent"><rich-text :nodes="item.content"></rich-text></view>
				<u-divider half-width="100%" :use-slot="false" color="#A1A4AA"></u-divider>
				<view class="noticeTime">{{item.time}}</view>
			</view>
		</block>
		<uni-load-more v-if="total > 0" :status="loadStatus"></uni-load-more>
		<view v-if="total == 0" style="margin-top: 200rpx;"><u-empty text="暂无公告" mode="news"></u-empty></view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				baseUrl:this.$baseUrl,
				noticeList:[],
				page:1,
				total:-1,
				loadStatus:'more'
			};
		},
		onLoad(options){
			if(options.uid){
				uni.setStorageSync('shareuid',options.uid)
			}
			this.getNotice()
		},
		methods:{
			// 获取公告
			async getNotice(){
				let res = await uni.$http('POST','home/noticeList',{limit:10,page:this.page})
				console.log('获取公告',res);
				if(res.code == 1 && res.data.length){
					if(this.page == 1){
						if(res.data.length < 10){
							this.loadStatus = 'nomore';
							this.noticeList = res.data;
						}else if(res.data.length == 10){
							this.loadStatus = 'nomore';
							this.noticeList = res.data;
						}
						this.total = res.data.length;
					}else{
						if(res.data.length < 10){
							this.loadStatus = 'nomore';
							this.noticeList = this.noticeList.concat(res.data)
						}else if(res.data.length == 10){
							this.loadStatus = 'nomore';
							this.noticeList = this.noticeList.concat(res.data)
						}
					}
				}else{
					this.loadStatus = 'nomore'
				}
			},
			// 前往公告详情
			toNoticeDetail(item){
				uni.navigateTo({
					url:"/pagesIndex/notice/detail?id="+item.id+"&data_type="+item.data_type
				})
				// if(item.data_type == 1){
				// 	uni.navigateTo({
				// 		url:"/pagesIndex/notice/detail?id="+item.id+"&data_type="+item.data_type
				// 	})
				// }else if(item.data_type == 2){
					
				// }
				
			}
		},
		onReachBottom() {
			console.log("触底")
			if (this.loadStatus != 'noMore') {
				this.loadStatus = 'loading'
				this.page++
				this.getNotice()
			}
		},
		// onShareAppMessage(){
		// 	let pages = getCurrentPages()
		// 	let prePage = pages[pages.length - 1];
		// 	return{
		// 		path:`/${prePage.route}?uid=${uni.getStorageSync('uid')}`
		// 	}
		// },
		// onShareTimeline() {
		// 	return{
		// 		query:`uid=${uni.getStorageSync('uid')}`
		// 	}
		// }
	}
</script>

<style scoped lang="less">
.pagesBox{
	padding: 16rpx 24rpx;
	.pagesMain{
		background-color: #fff;
		border-radius: 16rpx;
		padding: 16rpx 0;
		margin-bottom: 16rpx;
		.noticeTitle{
			font-weight: 600;
			font-size: 32rpx;
			color: #000;
			padding: 0 16rpx;
			display: flex;
			align-items: center;
			
		}
		.noticeContent{
			font-weight: 400;
			font-size: 28rpx;
			color: #A1A4AA;
			padding: 0 16rpx;
			margin: 20rpx 0;
			white-space:normal;
			word-break:break-all;
			word-wrap: break-word;
		}
		.noticeTime{
			font-weight: 400;
			font-size: 24rpx;
			color: #A1A4AA;
			padding: 0 16rpx;
			margin-top: 14rpx;
		}
	}
}
</style>
<style>
	page{
		background-color: #f7f8fa;
	}
</style>